package org.zfes.snowier.common.monitor.router;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.zfes.snowier.common.monitor.biz.model.ClassLoadEntity;
import org.zfes.snowier.common.monitor.biz.model.GcEntity;
import org.zfes.snowier.common.monitor.biz.model.MysqlMonitorEntity;
import org.zfes.snowier.common.monitor.biz.model.ThreadEntity;
import org.zfes.snowier.common.monitor.biz.service.ClassService;
import org.zfes.snowier.common.monitor.biz.service.GcService;
import org.zfes.snowier.common.monitor.biz.service.MysqlMonitorDataService;
import org.zfes.snowier.common.monitor.biz.service.ThreadService;
import com.alibaba.fastjson.JSONObject;
import java.util.List;


@Controller
public class WebSocketController {
//    @Autowired
//    private SimpMessagingTemplate messagingTemplate;
    @Autowired
    private GcService gcService;
    @Autowired
    private ClassService classService;
    @Autowired
    private ThreadService threadService;
    @Autowired
    private MysqlMonitorDataService mysqlService;
	

    @MessageMapping("/gc")
    @SendTo("/topic/gc")
    public List<GcEntity> socketGc(String instanceKey){
        return gcService.findAllByInstanceKey(instanceKey);
    }

    @MessageMapping("/cl")
    @SendTo("/topic/cl")
    public List<ClassLoadEntity> socketCl(String instanceKey){
        return classService.findAllByInstanceKey(instanceKey);
    }


    @MessageMapping("/thread")
    @SendTo("/topic/thread")
    public List<ThreadEntity> socketThread(String instanceKey){
        return threadService.findAllByInstanceKey(instanceKey);
    }

    
    @MessageMapping("/mysql")
    @SendTo("/topic/mysql")
    public List<MysqlMonitorEntity> socketMysql(String instanceKey){
        return mysqlService.findAllByInstanceKey(instanceKey);
    }

//    @MessageMapping("/weblog")
//    @SendTo("/topic/weblog")
//    public String weblog(String url){
//    	 JSONObject info=JSONObject.parseObject(HttpUtil.URLGet(url+"/actuator/info/logReader"));
//    	 if(info.containsKey("result")){
//    		 System.err.println(info.getString("result"));
//    		 return info.getString("result");
//    	 }else{
//    		 return "没有最新日志.......................";
//    	 }
//       
//    }
}
